package king.dominic.jlibrary.util;

import java.util.regex.Pattern;

/**
 * Created by Administrator on 2017/11/8.
 */

public class TextTool {
    private TextTool() {
    }

    public static String getNumber(CharSequence text) {
        return matcher(text, "[^0-9]");
    }

    public static String getDigits(CharSequence text, String... digits) {
        if (digits.length <= 0) return text.toString();
        StringBuilder builder = new StringBuilder();
        for (String d : digits) {
            builder.append("[");
            builder.append(d);
            builder.append("]");
        }
        return matcher(text, builder.toString());
    }

    public static String matcher(CharSequence text, String regular) {
        return Pattern.compile(regular).matcher(text).replaceAll("").trim();
    }
}
